package nl.saxion.act.wt;

import java.sql.Timestamp;
import java.util.ArrayList;

import org.apache.derby.impl.sql.catalog.SYSPERMSRowFactory;

import nl.saxion.act.dao.PersonDAO;

public class Auction {
	
	private int auctionID;
	private String title, description;
	private double price = 0.0;
	private Timestamp endTime;
	private int auctionStarterID;
	private ArrayList<Bid> allBids;
	private String catagory, highestBidderName, end;
	private PersonDAO p;
	
	public Auction( String title, String description, String catagory, double beginPrice, 
			Timestamp endTime, int auctionStarter ){
		this.title = title;
		this.description = description;
		this.auctionStarterID = auctionStarter;
		this.catagory = catagory;
		price = beginPrice;
		this.endTime = endTime;
		allBids = new ArrayList<Bid>();
		highestBidderName = "Er is nog niet geboden.";
	}
	
	public Auction(){
		allBids = new ArrayList<Bid>();
	}

	public int getAuctionID() {
		return auctionID;
	}

	public void setAuctionID(int auctionID) {
		this.auctionID = auctionID;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public Timestamp getEndTime() {
		return endTime;
	}

	public void setEndTime(Timestamp endTime) {
		this.endTime = endTime;
	}

	public int getAuctionStarterID() {
		return auctionStarterID;
	}

	public void setAuctionStarterID(int auctionStarterID) {
		this.auctionStarterID = auctionStarterID;
	}

	public ArrayList<Bid> getAllBids() {
		return allBids;
	}
	
	public void addBid(Bid bid){
		allBids.add(bid);
		highestBidderName = getHighestBidderName(); 
	}

	public void setAllBids(ArrayList<Bid> allBids) {
		this.allBids = allBids;
		highestBidderName = getHighestBidderName(); 
	}

	public String getCatagory() {
		return catagory;
	}

	public void setCatagory(String catagory) {
		this.catagory = catagory;
	}


	public String toString(){
		return title;
	}
	
	public void setHighestBidderName(String bidderName){
		this.highestBidderName = bidderName;
	}
	
	public String getHighestBidderName(){
//		Bid highestBid = null;
//		for(Bid bid : allBids){
//			if(highestBid == null || bid.getPrice() > highestBid.getPrice()){
//				highestBid = bid;
//			}
//		}
//		if(highestBid == null){
//			return "Nog niet geboden";
//		} else{
//	
//			return highestBid.getBidder()+"";
//			
//		}
		return highestBidderName;
			
	}
	
	public ArrayList<String> getAllBidderNames(){
		ArrayList<String> names = new ArrayList<String>();
		if(!getAllBids().isEmpty()){
			for(Bid b : getAllBids()){
				names.add(p.getBidderNameByID( b.getBidder() ));
			}
		} else{
			System.out.println("Bieding is leeg");
			names.add("Nog niet geboden");
		}
		return names;
	}
	
	public String getLastFewBidders(){
		for(int i = 0; i < 5; i++){
			highestBidderName += getAllBidderNames().get(i) + "/n";
		}
		return highestBidderName;
	}
}
